package ModelLayer;
import java.util.*;

/**
 * Write a description of class DVD here.
 * 
 * @author (Group1:Georgi,Roland and Mindaugas) 
 * @version (a version number or a date)
 */

   public class DVD
    {
     private long id;
     private String title;
     private String artist;
     private String publicationDate;
     private ArrayList<Copy> copies;
    /**
     * Constructor for objects of class DVD
     */
    public DVD(long id, String title, String artist , String publicationDate)
    {
        this.id=id;
        this.title=title;
        this.artist=artist;
        this.publicationDate=publicationDate;
        copies = new ArrayList<Copy>();
    }
    
    //Add copy to the list
    private void addCopy(Copy copy)
    {
        
        copies.add(copy);
    }
    
    /**
     * Creates a new Copy and add it to the list.
     */
    public void createCopy(long serialNumber, String purchaseDate, int purchasePrice)
    {
        if(searchCopy(serialNumber)==null)
        {
        Copy copy = new Copy(serialNumber, purchaseDate, purchasePrice);
        addCopy(copy);
        }
        
        else
          throw new RuntimeException();
    }
    
    /**
     * Searches for an existing copy using its Serial number.
     * @param the serial number of the copy.
     * @return the found copy
     */
    public Copy searchCopy(long serialNumber)  
    {
    for(int i = 0; i<copies.size(); i++){
           
           if(copies.get(i).getSerialNumber()==serialNumber){
               return copies.get(i);
            }
            
        }
        return null;
    }
    
        /**
         * Deletes and existing copy by searching for it an than deleting it using its Serial number.
         */
    public void deleteCopy(long serialNumber)
    {
        copies.remove(searchCopy(serialNumber));
        
    }
    
    /**
     * Searches through all the copies and checks if the copy we search for exists using its serial number.
     */
    public boolean copyExist(long idCopy)
    {
        if(searchCopy(idCopy)==null)
          return false;
          
        else
          return true;

    }
    
     //Accessor Methods
    
    public long getID()
    {
       return id;
    }

    public String getTitle()
    {
       return title;
    }
    
    public String getArtist()
    {
       return artist;
    }
    
    public String getPublicationDate()
    {
       return publicationDate;
    }
    
    
    
    //Mutator methods
    
    public void setID(long id)
    {
        this.id = id;
        
    }
    
    public void setTitle(String title)
    {
        this.title = title;
    }
    
    public void setArtist(String artist)
    {
        this.artist = artist;
        
    }
    
    public void setPublicationDate(String publicationDate)
    {
     this.publicationDate = publicationDate;   
    }

}
